//
//  HOTMainViewController.m
//  Genpara
//
//  Created by AndyChang.zhang on 14-8-27.
//  Copyright (c) 2014年 zhangchh. All rights reserved.
//

#import "HOTEntryViewController.h"
#import "HOTMenuViewController.h"
#import "ZZZPullDownView.h"
#import "ZZZPullDownModel.h"

#import "HOTSwitchBtn.h"

@interface HOTEntryViewController ()

@property(nonatomic,strong)UIBarButtonItem *barBtnItem;

@end

@implementation HOTEntryViewController

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

-(void)viewWillAppear:(BOOL)animated {
    
    [self setNavBarHidden:NO];
    
    [super viewWillAppear:animated];
}

-(void)viewWillDisappear:(BOOL)animated {
    
    [self setNavBarHidden:NO];
    
    [super viewWillDisappear:animated];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.navigationController.navigationBarHidden = YES;
    
//    HOTSwitchBtn *btn = [HOTSwitchBtn defaultSwitchBtn];
//    
//    [self.view addSubview:btn];
    
    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [leftBtn setImage:[UIImage imageNamed:@"btn_back"] forState:UIControlStateNormal];
    [leftBtn setImage:[UIImage imageNamed:@"btn_back_on"] forState:UIControlStateHighlighted];
    leftBtn.frame = CGRectMake(0, 0, 40, 40);
    [leftBtn setImageEdgeInsets:UIEdgeInsetsMake(0, -20, 0, 0)];
    [leftBtn addTarget:self action:@selector(dismissViewController) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftBarBtnItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
    [self.navigationItem setLeftBarButtonItem:leftBarBtnItem animated:YES];
}

- (void)dismissViewController
{
    [self.navigationController dismissViewControllerAnimated:YES completion:nil];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)entryBtnClicked:(id)sender {
    
//    HOTLoginViewController *loginVC = [[HOTLoginViewController alloc] initWithNibName:@"HOTLoginViewController" bundle:nil];
//    
//    [self.navigationController pushViewController:loginVC animated:YES];
    
//    HOTMenuViewController *menuVC = [[HOTMenuViewController alloc] initWithNibName:@"HOTMenuViewController" bundle:nil];
//    
//    [self.navigationController pushViewController:menuVC animated:YES];
    
//    HOTRegisterViewController *regVC = [[HOTRegisterViewController alloc] initWithNibName:@"HOTRegisterViewController" bundle:nil];
//    
//    [self.navigationController pushViewController:regVC animated:YES];
    
    
    
    HOTUserInfo *userInfo = [HOTUserInfo defaultUser];
    
    if ([userInfo isLogined]) {
        //上次登陆过
        
        if ([userInfo isAutoLogin]) {
            //自动登陆的场合
//            HOTMenuViewController *menuVC = [[HOTMenuViewController alloc] initWithNibName:@"HOTMenuViewController" bundle:nil];
//            [self.navigationController pushViewController:menuVC animated:YES];
            [self.navigationController dismissViewControllerAnimated:YES completion:nil];
        } else {
            
            HOTLoginViewController *logVc = [[HOTLoginViewController alloc] initWithNibName:@"HOTLoginViewController" bundle:nil];
            logVc.delegate = self;
            
            [self.navigationController pushViewController:logVc animated:YES];
        }
    } else {
        HOTRegisterViewController *regVC = [[HOTRegisterViewController alloc] initWithNibName:@"HOTRegisterViewController" bundle:nil];
        regVC.delegate = self;
        
        [self.navigationController pushViewController:regVC animated:YES];
    }
}

- (IBAction)loginBtnCLicked:(id)sender {
    
    HOTLoginViewController *logVc = [[HOTLoginViewController alloc] initWithNibName:@"HOTLoginViewController" bundle:nil];
    logVc.delegate = self;
    [self.navigationController pushViewController:logVc animated:YES];
}

#pragma mark - HOTLoginViewControllerDelegate

- (void)loginSuccessed
{
    if ([self.delegate respondsToSelector:@selector(entrySuccessed)]) {
        [self.delegate entrySuccessed];
    }
}

#pragma mark - HOTRegisterViewControllerDelegate

- (void)registerSuccessed
{
    if ([self.delegate respondsToSelector:@selector(entrySuccessed)]) {
        [self.delegate entrySuccessed];
    }
}


@end
